public class Niuke_1 {
    import java.util.Scanner;

    // 注意类名必须为 Main, 不要有任何 package xxx 信息
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] arr = new int[10000];
            int max = 0;
            int maxx = arr[0];
            for(int i = 0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            for(int j = 0; j<n-1;){
                if((arr[j] + arr[j+1])>arr[j]){
                    max=max+arr[j]+arr[j+1];
                    j=j+2;
                }
                else{
                    maxx = max;
                    max = 0;
                    j++;
                }
            }
            maxx = max;
            return maxx;
        }
    }
}
